package com.example.eos.controller;

import com.example.eos.bean.ReturnInfo;
import com.example.eos.bean.Wallet;
import com.example.eos.service.HttpService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class WalletController {

    //创建一个新的钱包
    @RequestMapping(value = "/wallet/creat/{walletname}",method = RequestMethod.POST)
    public ReturnInfo creatWallet(@PathVariable String walletname){
        //返回解锁钱包的密码
        String info = HttpService.DoPost("http://192.168.81.130:8889/v1 /wallet/create",walletname);
        return ReturnInfo.info1(info);
    }

    //打开一个钱包
    @RequestMapping(value = "/wallet/open/{walletname}",method = RequestMethod.POST)
    public ReturnInfo openWallet(@PathVariable String walletname){
        String info = HttpService.DoPost("http://192.168.81.130:8889/v1/wallet/open",walletname);
        return ReturnInfo.info1(info);
    }

    //锁定一个钱包
    @RequestMapping(value = "/wallet/lock/{walletname}",method = RequestMethod.POST)
    public ReturnInfo lockWallet(@PathVariable String walletname){
        String info = HttpService.DoPost("http://192.168.81.130:8889/v1/wallet/lock",walletname);
        return ReturnInfo.info1(info);
    }

    //锁定所有钱包
    @RequestMapping(value = "/wallet/lockall",method = RequestMethod.GET)
    public ReturnInfo lockAllWallet(){
        String info = HttpService.DoGet("http://192.168.81.130:8889/v1/wallet/lock_all");
        return ReturnInfo.info1(info);
    }

    //解锁钱包
    @RequestMapping(value = "/wallet/unlock",method = RequestMethod.POST)
    public ReturnInfo unlockWallet(@RequestBody Wallet wallet){
        String string = wallet.toString();
        String info = HttpService.DoPost("http://192.168.81.130:8889/v1/wallet/unlock", string);
        return ReturnInfo.info1(info);
    }

    //将私钥导入给定名称的钱包
    @RequestMapping(value = "/wallet/key",method = RequestMethod.POST)
    public ReturnInfo importKey(@RequestBody Wallet wallet){
        String string = wallet.toString();
        String info = HttpService.DoPost("http://192.168.81.130:8889/v1/wallet/import_key", string);
        return ReturnInfo.info1(info);
    }

    //列出所有钱包
    @RequestMapping(value = "/wallet/listwallets",method = RequestMethod.GET)
    public ReturnInfo listWallets(){
        String info = HttpService.DoGet("http://192.168.81.130:8889/v1/wallet/list_wallets");
        return ReturnInfo.info1(info);
    }

    //列出所有钱包中的所有密钥对
    @RequestMapping(value = "/wallet/listkeys",method = RequestMethod.GET)
    public ReturnInfo listKeys(){
        String info = HttpService.DoGet("http://192.168.81.130:8889/v1/wallet/list_keys");
        return ReturnInfo.info1(info);
    }

    //列出所有钱包中的所有公钥
    @RequestMapping(value = "/wallet/publickeys",method = RequestMethod.GET)
    public ReturnInfo publicKeys(){
        String info = HttpService.DoGet("http://192.168.81.130:8889/v1/wallet/get_public_keys");
        return ReturnInfo.info1(info);
    }

//    //设置钱包自动锁定超时（以秒为单位）
//    @RequestMapping(value = "wallet/timeout",method = RequestMethod.POST)
//    public ReturnInfo SetTimeout(@RequestParam Integer timeout){
//
//    }

}
